package com.leo.study.billingstrategy;

import java.util.ArrayList;

/**
 * @author liusl
 * @date 2019/3/13-11:04
 */
public class Customer {

    private final ArrayList<Integer> drinks = new ArrayList<>();
    private IBillingStrategy strategy;

    public Customer(IBillingStrategy strategy) {
        this.strategy = strategy;
    }

    public void add(int price, int quantity) {
        this.drinks.add(this.strategy.getActPrice(price * quantity));
    }

    /**
     * 支付账单
     */
    public void printBill() {
        int sum = this.drinks.stream().mapToInt(v -> v).sum();
        System.out.println("Total due: " + sum / 100.0);
        this.drinks.clear();
    }

    /**
     * 制定战略
     */
    public void setStrategy(IBillingStrategy strategy) {
        this.strategy = strategy;
    }
}
